package cn.baage.campus.controller;

import cn.baage.campus.annotation.ApiLog;
import cn.baage.campus.constant.validation.AddGroup;
import cn.baage.campus.constant.validation.UpdateGroup;
import cn.baage.campus.enums.BusinessType;
import cn.baage.campus.enums.OperateType;
import cn.baage.campus.model.po.User;
import cn.baage.campus.service.UserService;
import cn.baage.campus.utils.Result;
import com.alibaba.fastjson2.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 用户接口
 * @Author: 八阿哥
 * @url: baage.cn
 * @Version: 1.0
 **/
@RestController
@RequestMapping("/user")
@Api(tags = "用户接口")
@RequiredArgsConstructor(onConstructor_= @Autowired)
public class UserController {


    private final UserService userService;


    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @GetMapping("/getById")
    @ApiOperation(value = "获取指定用户")
    public Result<User> getUserById(String userId) {
        return Result.success(userService.getById(userId));
    }


    @PostMapping("/add")
    @ApiOperation(value = "新增用户")
    @ApiLog(operateType = OperateType.INSERT, businessType = BusinessType.SYSTEM)
    public Result<Object> addUser(@Validated(value = {AddGroup.class}) @RequestBody User user) {
        System.out.println(JSON.toJSONString(user));
        return Result.success();
    }


    @PostMapping("/update")
    @ApiOperation(value = "修改用户")
    @ApiLog(operateType = OperateType.UPDATE, businessType = BusinessType.SYSTEM)
    public Result<Object> updateUser(@Validated(value = {UpdateGroup.class}) @RequestBody User user) {
        System.out.println(JSON.toJSONString(user));
        return Result.success();
    }




}
